home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / xlib06p1.zip / XCIRCLE.CPP < prev    next >
C/C++ Source or Header  |  1995-03-15  |  3KB  |  117 lines

  1. #include "xinternl.h"
  2. #include "xpoint.h"
  3.  
  4. /*
  5. much of this code is horked from the w_modex.zip code, the author of
  6. which I can not remember.
  7.  
  8. Modified 1995 by Victor B. Putz
  9. */
  10.  
  11. void x_circle (
  12.     xScreenCoord_t Left,
  13.     xScreenCoord_t Top,
  14.     int Diameter,
  15.   xColor_t Color,
  16.     xPageHandle_t ScreenOffs
  17. )
  18. {
  19.     int Radius = Diameter / 2;
  20.     int x = Left + Radius + 1;
  21.   int y = Top + Radius + 1;
  22.   int ix, iy, d, deltaE, deltaSE;
  23.  
  24.   ix = 0;
  25.   iy = Radius;
  26.   d = 1 - Radius;
  27.   deltaE = 3;
  28.   deltaSE = (-2 * Radius) + 5;
  29.  
  30.   x_put_pix(x + ix, y + iy, ScreenOffs, Color);
  31.   x_put_pix(x + ix, y - iy, ScreenOffs, Color);
  32.   x_put_pix(x + iy, y + ix, ScreenOffs, Color);
  33.   x_put_pix(x + iy, y - ix, ScreenOffs, Color);
  34.   x_put_pix(x - ix, y + iy, ScreenOffs, Color);
  35.   x_put_pix(x - ix, y - iy, ScreenOffs, Color);
  36.   x_put_pix(x - iy, y + ix, ScreenOffs, Color);
  37.   x_put_pix(x - iy, y - ix, ScreenOffs, Color);
  38.  
  39.   while (iy > ix++) {
  40.     if (d < 0) {
  41.       d += deltaE;
  42.       deltaE += 2;
  43.       deltaSE += 2;
  44.     } else {
  45.       d += deltaSE;
  46.       deltaE += 2;
  47.       deltaSE += 4;
  48.       iy--;
  49.     }
  50.  
  51.     x_put_pix(x + ix, y + iy, ScreenOffs, Color);
  52.     x_put_pix(x + ix, y - iy, ScreenOffs, Color);
  53.     x_put_pix(x + iy, y + ix, ScreenOffs, Color);
  54.     x_put_pix(x + iy, y - ix, ScreenOffs, Color);
  55.     x_put_pix(x - ix, y + iy, ScreenOffs, Color);
  56.     x_put_pix(x - ix, y - iy, ScreenOffs, Color);
  57.     x_put_pix(x - iy, y + ix, ScreenOffs, Color);
  58.     x_put_pix(x - iy, y - ix, ScreenOffs, Color);
  59.   }
  60. }
  61.  
  62.  
  63.  
  64. extern void _HorizontalLine(
  65.     xPageHandle_t wOffset,
  66.     int iLeftX,
  67.     int iY,
  68.     int iLength,
  69.     int iColor
  70. );
  71.  
  72. void x_filled_circle (
  73.     xScreenCoord_t Left,
  74.     xScreenCoord_t Top,
  75.     int Diameter,
  76.   xColor_t Color,
  77.     xPageHandle_t ScreenOffs
  78. )
  79. {
  80.     int Radius = Diameter / 2;
  81.   //round to the nearest even coordinate center (for some reason it
  82.   //likes this-- don't have time to see why)
  83.   int x = (Left + Radius);
  84.   int y = (Top + Radius);
  85.   int ix, iy, d, deltaE, deltaSE;
  86.  
  87.   ix = 0;
  88.   iy = Radius;
  89.   d = 1 - Radius;
  90.   deltaE = 3;
  91.   deltaSE = (-2 * Radius) + 5;
  92.  
  93.   _HorizontalLine( ScreenOffs, x - ix, y + iy, (ix << 1) + 1, Color);
  94.   _HorizontalLine( ScreenOffs, x - ix, y - iy, (ix << 1) + 1, Color);
  95.   _HorizontalLine( ScreenOffs, x - iy, y + ix, (iy << 1) + 1, Color);
  96.   _HorizontalLine( ScreenOffs, x - iy, y - ix, (iy << 1) + 1, Color);
  97.  
  98.   while (iy > ix++) {
  99.     if (d < 0) {
  100.       d += deltaE;
  101.       deltaE += 2;
  102.       deltaSE += 2;
  103.     } else {
  104.       d += deltaSE;
  105.       deltaE += 2;
  106.       deltaSE += 4;
  107.       iy--;
  108.     }
  109.  
  110.     _HorizontalLine( ScreenOffs, x - ix, y + iy, (ix << 1) + 1, Color);
  111.     _HorizontalLine( ScreenOffs, x - ix, y - iy, (ix << 1) + 1, Color);
  112.     _HorizontalLine( ScreenOffs, x - iy, y + ix, (iy << 1) + 1, Color);
  113.     _HorizontalLine( ScreenOffs, x - iy, y - ix, (iy << 1) + 1, Color);
  114.   }
  115. }
  116.  
  117.